<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    /*重新设置样式*/
    .form-control {
        width: 196px !important;
        height: 34px !important;
        padding: 10px !important;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini" onload="checkBrowser()">


<!--选择外购件库存模态框-->
<div class="modal fade" id="modal-select-purchase">
    <div class="modal-dialog" style="width: 1350px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">外购件库在库明细信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">
                                <form id="modalQueryForm">
                                    <div class="row" id="HiddenDiv">
                                        <div class="form-inline">
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>项目编号</label>
                                                <input type="text" id="ityProCode" name="ityProCode"
                                                       class="form-control"
                                                       placeholder="请输入项目编号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>项目名称</label>
                                                <input type="text" id="ityProName" name="ityProName"
                                                       class="form-control"
                                                       placeholder="请输入项目名称">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    物料描述
                                                </label>
                                                <input type="text" id="ityMatDesc" name="ityMatDesc"
                                                       class="form-control"
                                                       placeholder="请输入物料描述">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    SAP物料编码
                                                </label>
                                                <input type="text" id="itySapCode" name="itySapCode"
                                                       class="form-control"
                                                       placeholder="请输入SAP物料编码">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>跟踪号</label>
                                                <input type="text" id="ityTrackCode" name="ityTrackCode"
                                                       class="form-control"
                                                       placeholder="请输入跟踪号">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    库位
                                                </label>
                                                <input type="text" id="ityPosition" name="ityPosition"
                                                       class="form-control"
                                                       placeholder="请输入库位">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>仓库</label>
                                                <select id="ityWhiId" class="form-control select" name="ityWhiId"
                                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;">
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <label>
                                                    生产状态
                                                </label>
                                                <select id="proProductionStatus" name="proProductionStatus"
                                                        class="form-control select">
                                                    <option value="" selected="selected">全部</option>
                                                    <option value="-1">无状态</option>
                                                    <option value="1">未开始</option>
                                                    <option value="2">执行中</option>
                                                    <option value="3">已完成</option>
                                                    <option value="4">取消</option>
                                                    <option value="5">暂缓</option>
                                                </select>
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                                <button type="button" class="btn btn-success" id="btn_inventorySearch">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="box-body"
                                 style="padding-top: 0px;padding-bottom: 0px;height: 600px">
                                <table id="inventoryQueryTable" class="table table-bordered " width="100%"
                                       data-height="400">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">
                <button type="button" class="btn btn-info" id="btn-selectMaterial-commit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>

</div>
<section class="content-header">
    <h1>库存划项目申请</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        物料描述
                                    </label>
                                    <label class="control-label">
                                        <input name="ipmMatDesc" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入物料描述"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="ipmInProjectCode" type="text" class="form-control text"

                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        项目名称
                                    </label>
                                    <label class="control-label">
                                        <input name="ipmInProjectName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        标记人
                                    </label>
                                    <label class="control-label">
                                        <input name="ipmProposer" type="text" class="form-control text" maxlength="255"
                                               placeholder="请输入标记人信息"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        被标记物料项目编号
                                    </label>
                                    <label class="control-label">
                                        <input name="ityProCode" type="text" class="form-control text"

                                               placeholder="请输入被标记物料项目编号"/>
                                    </label>
                                </div>
                                <div id="ipmRemoveUserName" class="form-group"
                                     style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        申请删除者
                                    </label>
                                    <label class="control-label">
                                        <input name="ipmRemoveUserName" type="text" class="form-control text"
                                               maxlength="255"
                                               placeholder="请输入申请删除者"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        状态
                                    </label>
                                    <label class="control-label">
                                        <select name="ipmAppStatusTextSelect" class="selectpicker"
                                                multiple data-actions-box="true"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                            <option value="1" selected>未提交</option>
                                            <option value="2" selected>被驳回</option>
                                            <option value="3">已提交</option>
                                            <option value="4">已执行</option>
                                            </option>
                                        </select>
                                    </label>
                                    <input name="ipmAppStatusText" type="hidden" style="display: none" value="1,2"/>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        仓库
                                    </label>
                                    <label class="control-label">
                                        <select name="ityWhiId" class="form-control select"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">

                                        </select>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        删除状态
                                    </label>
                                    <label class="control-label">
                                        <select name="ipmDataStatusStr" class="form-control"
                                                style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: 60px!important;">
                                            <!--<option value="-1">全部</option>-->
                                            <option value="">全部</option>
                                            <option value="0" selected="selected">未删除</option>
                                            <option value="1">已删除</option>
                                        </select>
                                    </label>
                                </div>
                                <div id="removeDate" class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        删除日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginRemoveDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endRemoveDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>
                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        标记时间
                                    </label>

                                    <input name="beginDate" type="text"
                                           class="form-control datepicker" style="width: 100px!important;"
                                           readonly="readonly"> -
                                    <input name="endDate" type="text"
                                           class="form-control datepicker" style="width: 100px!important;"
                                           readonly="readonly">
                                </div>
                                <div id="submitDate" class="form-group" style="margin-right: 10px;margin-bottom: 5px">
                                    <label class="control-label" style="text-align: right">
                                        提交日期范围
                                    </label>
                                    <label class="control-label">
                                        <input name="beginSubmitDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>-
                                        <input name="endSubmitDate" type="text" class="form-control datepicker"
                                               style="width:100px!important;text-align: center!important;"
                                               readonly="readonly"/>
                                    </label>
                                </div>

                                <div class="form-group" style="padding-right: 10px;padding-bottom: 5px">
                                    <button type="button" class="btn btn-success" id="btn-search">搜索
                                    </button>
                                </div>
                            </div>
                        </div>

                    </form>
                </div>
                <div id="toolbar">
                    <button shiro:hasPermission="purinv:purwarpro:edit" type="button" class="btn btn-success"
                            onclick="submitAppy('')">
                        批量提交
                    </button>
                    <a shiro:hasPermission="purinv:purwarpro:edit" href="/purchase/invPro/createPage"
                       class="btn btn-info" id="btn-add-flag">新增标记</a>

<!--                    <a shiro:hasPermission="purinv:purwarpro:edit" href="/purchase/invPro/importPage"-->
<!--                       class="btn btn-info">批量标记导入</a>-->
                    <button shiro:hasPermission="purinv:purwarpro:edit"
                            class="btn btn-danger" id="btn-del-items">批量删除
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>
<!--库存划项目标记模态框-->
<div class="modal fade" id="modal-inventory-project">
    <div class="modal-dialog" style="width:500px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">库存划项目标记编辑</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header">
                            </div>
                            <div class="box-body">
                                <form id="modalForm" class="form-horizontal" role="form">
                                    <input type="hidden" name="ipmId">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <input type="hidden" name="ipmBeforeItyId">
                                                <label class="control-label col-sm-5"
                                                       for="ityMatDescModal">外购件物料描述</label>
                                                <div class="col-sm-6">
                                                    <input name="ityMatDesc" id="ityMatDescModal" class="form-control"
                                                           type="text"
                                                           readonly="readonly"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <input type="hidden" name="ipmBeforeItyId">
                                                <label class="control-label col-sm-5"
                                                       for="ipmMatDesc">提报计划物料描述</label>
                                                <div class="col-sm-6">
                                                    <input name="ipmMatDesc" id="ipmMatDesc" class="form-control"
                                                           type="text" maxlength="255"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <label class="control-label col-sm-5"
                                                       for="ipmInProjectCodeModal">新项目编号</label>
                                                <div class="col-sm-6">
                                                    <input name="ipmInProjectCode"
                                                           id="ipmInProjectCodeModal"
                                                           class="form-control" type="text"
                                                           list="ceoNeedProCodeList"
                                                           onchange="changeIpmInProjectName()"
                                                           oninput="findProCodeListData(this)"/>
                                                    <datalist id="ceoNeedProCodeList">
                                                    </datalist>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <label class="control-label col-sm-5"
                                                       for="ipmInProjectNameModal">新项目名称</label>
                                                <div class="col-sm-6">
                                                    <input name="ipmInProjectName" id="ipmInProjectNameModal"
                                                           class="form-control" type="text"
                                                    />
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <label class="control-label col-sm-5" for="ityAvaNumModal">可用数量</label>
                                                <div class="col-sm-5" style="padding-right: 0px">
                                                    <input name="ityAvaNum" id="ityAvaNumModal" class="form-control"
                                                           type="text" style="width: 160px!important;"
                                                           readonly="readonly"/>

                                                </div>
                                                <div class="col-sm-1" style="margin: 0;padding: 0px">
                                                    <input name="ityAvaNumUnit" id="ityAvaNumUnitModal"
                                                           class="form-control"
                                                           style="background-color: white;border-color: white;color: black;width: 50px!important;padding: 0px"
                                                           type="text"
                                                           readonly="readonly"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <label class="control-label col-sm-5" for="ipmNumModal">标记数量</label>
                                                <div class="col-sm-5" style="padding-right: 0px">
                                                    <input name="ipmNum" maxlength="9" id="ipmNumModal"
                                                           oninput="checkValue(this)" style="width: 160px!important;"
                                                           class="col-sm-5 form-control" type="text"/>
                                                </div>
                                                <div class="col-sm-1" style="margin: 0;padding: 0px">
                                                    <input name="ipmNumUnit" id="ipmNumUnitModal"
                                                           class="col-sm-3 form-control"
                                                           style="background-color: white;border-color: white;color: black;width: 50px!important;padding: 0px"

                                                           type="text"
                                                           readonly="readonly"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <label class="control-label col-sm-5" for="ipmRemarkModal">备注</label>
                                                <div class="col-sm-6">
                                                    <input name="ipmRemark" id="ipmRemarkModal" class="form-control"
                                                           type="text" maxlength="255"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group" style="height: 60px">
                                                <label class="control-label col-sm-5" for="ipmRemarkModal">标准号</label>
                                                <div class="col-sm-6">
                                                    <input name="ipmStandardNo" id="ipmStandardNo" class="form-control"
                                                           type="text" maxlength="255"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-info" id="btn-save">保存</button>
                <button class="btn btn-warning" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var applyStatusText = ["删除", "未提交", "被驳回", "已提交", "已执行"];
    var applyStatusColor = ["", " bg-gray", " bg-red", " bg-green", " bg-green"];
    var columns = new Array();

    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }

    /**
     * 检测浏览器
     * */
    function checkBrowser(){
        if(!checkBrowserFun()){
            alert("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href=ctx+"overview/index";
        }
    }

    /**
     * 初始化页面中搜索框中元素的显隐
     **/
    function initQueryFormControl() {
        $("#ipmRemoveUserName").hide();
        $("#removeDate").hide();
        columns = [
            {
                title: '<input style="width: 16px;height: 16px" title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                width: '30',
                field: 'ipmId',
                formatter: function (value, row, index) {
                    var disabled = 'disabled="disabled"';
                    if (row.ipmAppStatus == 1 || row.ipmAppStatus == 2) {
                        disabled = "";
                    }
                    var sessionUser = [[${session.user}]];
                    if (row.ipmProposerId != sessionUser.id) {
                        disabled = 'disabled="disabled"';
                    } else {
                        disabled = "";
                    }
                    return '<input  style="width: 16px;height: 16px" ' + disabled + ' id="cb_change' + row.ipmId + '" name="cb_change" data="' + row.ipmId + '"  type="checkbox" />';
                }
            },
            {
                title: '序号', field: 'ipmId', width: '50',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {title: '提报计划物料描述', field: 'ipmMatDesc', width: '150'},
            {title: '标记数量', field: 'ipmNum'},
            {title: '单位', field: 'ityNumUnit', width: '50'},
            {title: '单价', field: 'ipmPrice', formatter: function (value, row, index) {
                    if(hasP('purinv:amount:view')){
                        return value;
                    }else {
                        return "***";
                    }
                }},
            {title: '提报计划物料标准号', field: 'ipmStandardNo'},
            {
                title: '项目编号', field: 'ipmInProjectCode', formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return value;
                }
            },
            {
                title: '项目名称', field: 'ipmInProjectName', width: '150', formatter: function (value, row, index) {
                    if (value == undefined || value == null) {
                        value = "--";
                    }
                    return value;
                }
            },
            // {
            //     title: '仓库类型', field: 'ipmItyType', width: '150', formatter: function (value, row, index) {
            //         if (value == undefined) {
            //             return "";
            //         }
            //         if (value == 'p') {
            //             return "外购件库";
            //         }
            //         if (value == 'm') {
            //             return "原料库";
            //         }
            //         if (value == 'h') {
            //             return "成品库";
            //         }
            //         return value;
            //     }
            // },
            {title: '仓库', field: 'ityWhiName'},
            {
                title: '标记人', field: 'ipmProposer', width: '70'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },

            {
                title: '标记时间', field: 'ipmDatePage', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },

            {
                title: '被标记物料项目编号', field: 'ityProCode', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '被标记物料项目名称', field: 'ityProName', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '提交时间', field: 'ipmSubmitDate', width: '100'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '划拨说明', field: 'ipmRemark'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '划拨状态', field: 'ipmAppStatus'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    var html = '<label class="badge ' + applyStatusColor[value] + '">' + applyStatusText[value] + '</label>';
                    return html;
                }
            },
            {
                title: '驳回原因', field: 'ipmRejectReason'
                , formatter: function (value, row, index) {
                    if (value == undefined) {
                        return "";
                    }
                    return value;
                }
            },
            {
                title: '操作', field: 'ipmId', width: '140',
                formatter: function (value, row, index) {
                    var htmlText = "";

                    if (row.ipmDataStatus == null && (row.ipmAppStatus == 1 || row.ipmAppStatus == 2)) {
                        if (hasP('purinv:purwarpro:edit')) {
                            htmlText += '<button class="btn btn-info btn-xs" onclick="submitAppy(' + row.ipmId + ')">提交</button>';
                            htmlText += '<button  onclick="showEditPanel(' + row.ipmId + ')" class="btn btn-xs btn-warning">修改</button>';
                        }
                        if (hasP('purinv:purwarpro:del')) {
                            htmlText += '<button  onclick="removeAppy(' + row.ipmId + ')" class="btn btn-xs btn-danger">删除</button>';

                        }
                    }
                    return htmlText;
                }
            }
        ];
    }

    /**
     * 初始化数据
     * */
    function initData() {

        $('#bootstrap-table').bootstrapTable('destroy');
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "purchase/invPro/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            striped: false,
            uniqueId: "ipmId",
            onLoadSuccess: function () {
                $('#inventoryQueryTable thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#inventoryQueryTable tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
            },
            columns: columns
        });
    }


    /**
     *@FunctionName: findWarehouseList
     *@Description: 获取仓库列表
     *@DesignIdea: 因为此页面是外购件页面，所以获取外购件仓库列表。
     *@Author: 徐一贺
     *@CreateDate: 2020/5/9 16:10
     *@Phone: 18241927380
     *@Param: []
     *@Version: v 1.0.0
     */
    function findWarehouseList() {
        js.ajax({
            url: ctx + 'common/warehouseInfo/list',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {

                    $("#queryForm [name='ityWhiId']").empty();
                    $("#queryForm [name='ityWhiId']").append('<option selected="selected" style="vertical-align: middle;text-align: center" value="">全部</option>');
                    for (var i = 0; i < result.data.rows.length; i++) {
                        $("#queryForm [name='ityWhiId']").append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     *@FunctionName: findProCodeListData
     *@Description: 根据项目号模糊查询获取项目号列表
     *@Author: 徐一贺
     *@CreateDate: 2020/4/18 12:59
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function findProCodeListData(obj) {
        $.post(ctx + 'purchase/invPro/findProCodeList', {
            code: $(obj).val()
        }, function (result) {
            if (result.type == 'SUCCESS') {
                $("#ceoNeedProCodeList").empty();
                for (var i = 0; i < result.data.length; i++) {
                    $("#ceoNeedProCodeList").append('<option value="' + result.data[i].code + '" data="' + result.data[i].name + '" data-status="' + result.data[i].status + '"></option>');
                }
            }
        }, 'json');
    }

    function changeIpmInProjectName() {
        var input_select = $("#modalForm [name='ipmInProjectCode']").val();
        var option_length = $("#ceoNeedProCodeList").find("option").length;
        for (var i = 0; i < option_length; i++) {
            if (input_select == $("#ceoNeedProCodeList option").eq(i).attr('value')) {
                $("#modalForm [name='ipmInProjectName']").val($("#ceoNeedProCodeList option").eq(i).attr("data"));
                break;
            }
        }
    }

    /**
     *@FunctionName: checkValue
     *@Description: 检测控制其值不可大于库存可用数量
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 19:23
     *@Phone: 18241927380
     *@Param:
     *@Return:
     *@Version:
     */
    function checkValue(obj) {
        xyh.inputDecimalThree(obj);
        var compareValue = $("#modalForm [name='ityAvaNum']").val();
        if (compareValue != undefined && compareValue != null && compareValue != '') {
            if (Number($(obj).val()) > Number(compareValue)) {
                $(obj).val(compareValue);
            }
        }
    }

    /**
     *@FunctionName: submitAppy
     *@Description: 提交
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 12:35
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function submitAppy(ipmId) {
        if (ipmId == '') {
            $('input[name="cb_change"]').each(function () {
                if (!$(this).prop("disabled")) {
                    if ($(this).prop("checked")) {
                        ipmId += $(this).attr("data") + ",";
                    }
                }
            })
            ipmId = ipmId.substring(0, ipmId.length - 1);
        } else {
            var data = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', ipmId);
            var sessionUser = [[${session.user}]];
            if (data.ipmProposerId != sessionUser.id) {
                js.modal.warning("尊敬的用户，您只可以提交自己的申请！");
                return false;
            }
        }
        if (ipmId == '') {
            js.modal.alert("请选择要提交的库存划项目申请！");
            return;
        }
        js.modal.confirm("您确认要提交此标记吗？", function () {
            $("#bootstrap-table").hide();
            $("#toolbar").hide();
            $.post(ctx + 'purchase/invPro/submitAppy', {
                ipmIds: ipmId
            }, function (result) {
                js.table.refresh(table);
                $("#bootstrap-table").show();
                $("#toolbar").show();
            }, 'json');
        });
    }

    /**
     *@FunctionName: showEditPanel
     *@Description: 打开编辑模态框
     *@Author: 徐一贺
     *@CreateDate: 2020/5/14 13:16
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function showEditPanel(ipmId) {
        var data = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', ipmId);
        var sessionUser = [[${session.user}]];
        if (data.ipmProposerId != sessionUser.id) {
            js.modal.warning("尊敬的用户，您只可以修改自己的申请！");
            return false;
        }
        js.post({
            url: ctx + 'purchase/invPro/getInfo',
            data: {ipmId: ipmId},
            dataType: 'json',
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#modalForm").fillData(result.data);

                    // js.modal.success(result.msg);
                    js.modal.open("modal-inventory-project");
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }

        })
    }


    /**
     *@FunctionName: removeAppy
     *@Description: 删除作废
     *@Author: 徐一贺
     *@CreateDate: 2020/4/21 13:09
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function removeAppy(ipmId) {
        if (ipmId == '') {
            $('input[name="cb_change"]').each(function () {
                if (!$(this).prop("disabled")) {
                    if ($(this).prop("checked")) {
                        ipmId += $(this).attr("data") + ",";
                    }
                }
            })
            ipmId = ipmId.substring(0, ipmId.length - 1);
        } else {
            var data = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', ipmId);
            var sessionUser = [[${session.user}]];
            if (data.ipmProposerId != sessionUser.id) {
                js.modal.warning("尊敬的用户，您只可以删除自己的申请！");
                return false;
            }
        }
        if (ipmId == '') {
            js.modal.alert("请选择要删除的库存划项目申请！");
            return;
        }
        js.modal.confirm("您确认要删除选中的标记吗？", function () {
            $("#bootstrap-table").hide();
            $("#toolbar").hide();
            $.post(ctx + 'purchase/invPro/removeAppy', {
                ipmIds: ipmId
            }, function (result) {
                if (result.type == "SUCCESS") {
                    $("#selectAll").prop('checked', false);
                }
                js.table.refresh(table);
                $("#bootstrap-table").show();
                $("#toolbar").show();
            }, 'json');
        });
    }


    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: 徐一贺
     *@CreateDate: 2020/4/10 16:10
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    /**
     *@FunctionName: selectAll
     *@Description: 全选
     *@Author: 徐一贺
     *@CreateDate: 2020/4/8 15:20
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function selectAll(obj) {
        $('input[name="cb_change"]').each(function () {
            if (!$(this).prop("disabled")) {
                if ($(obj).prop("checked")) {
                    $(this).prop("checked", true);
                }
                if ($(obj).prop("checked") == false) {
                    $(this).prop("checked", false);
                }
            }
        })
    }


    $(function () {
        $("title").html($("title").html()+" —— 外购件库存划项目申请");
        findWarehouseList();
        initQueryFormControl();
        initData();
        $("#queryForm [name='ipmAppStatusTextSelect']").change(function () {
            $("#queryForm input[name='ipmAppStatusText']").val($("#queryForm [name='ipmAppStatusTextSelect']").val());
        });
        /**
         * 当选择删除状态时
         */
        $("#queryForm [name='ipmDataStatusStr']").change(function () {
            if ($(this).val() === '1' || $(this).val() === '') {
                $("#ipmRemoveUserName").show();
                $("#removeDate").show();
                $("#toolbar").hide();
                columns = [
                    {
                        title: '<input style="width: 16px;height: 16px" title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                        width: '30',
                        field: 'ipmId',
                        formatter: function (value, row, index) {
                            var disabled = 'disabled="disabled"';
                            if (row.ipmAppStatus == 1 || row.ipmAppStatus == 2) {
                                disabled = "";
                            }
                            var sessionUser = [[${session.user}]];
                            if (row.ipmProposerId != sessionUser.id) {
                                disabled = 'disabled="disabled"';
                            } else {
                                disabled = "";
                            }
                            return '<input  style="width: 16px;height: 16px" ' + disabled + ' id="cb_change' + row.ipmId + '" name="cb_change" data="' + row.ipmId + '"  type="checkbox" />';
                        }
                    },
                    {
                        title: '序号', field: 'ipmId', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {title: '提报计划物料描述', field: 'ipmMatDesc', width: '150'},
                    {title: '标记数量', field: 'ipmNum'},
                    {title: '单位', field: 'ityNumUnit', width: '50'},
                    {title: '提报计划物料标准号', field: 'ipmStandardNo'},
                    {
                        title: '项目编号', field: 'ipmInProjectCode', formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    {
                        title: '项目名称',
                        field: 'ipmInProjectName',
                        width: '150',
                        formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    // {
                    //     title: '仓库类型', field: 'ipmItyType', width: '150', formatter: function (value, row, index) {
                    //         if (value == undefined) {
                    //             return "";
                    //         }
                    //         if (value == 'p') {
                    //             return "外购件库";
                    //         }
                    //         if (value == 'm') {
                    //             return "原料库";
                    //         }
                    //         if (value == 'h') {
                    //             return "成品库";
                    //         }
                    //         return value;
                    //     }
                    // },
                    {title: '仓库', field: 'ityWhiName'},
                    {
                        title: '标记人', field: 'ipmProposer', width: '70'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '标记时间', field: 'ipmDatePage', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '被标记物料项目编号', field: 'ityProCode', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '提交时间', field: 'ipmSubmitDate', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '划拨说明', field: 'ipmRemark'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '划拨状态', field: 'ipmAppStatus'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            var html = '<label class="badge ' + applyStatusColor[value] + '">' + applyStatusText[value] + '</label>';
                            return html;
                        }
                    },
                    {
                        title: '驳回原因', field: 'ipmRejectReason'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '删除状态', field: 'ipmDataStatus'
                        , formatter: function (value, row, index) {
                            if (value === '1') {
                                return "删除";
                            } else {
                                return "未删除";
                            }
                        }
                    },
                    {
                        title: '删除操作者', field: 'ipmRemoveUserName'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '删除时间', field: 'ipmRemoveDate'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '操作', field: 'ipmId', width: '140',
                        formatter: function (value, row, index) {
                            var htmlText = "";
                            if (row.ipmDataStatus == null && (row.ipmAppStatus == 1 || row.ipmAppStatus == 2)) {
                                if (hasP('purinv:purwarpro:edit')) {
                                    htmlText += '<button class="btn btn-info btn-xs" onclick="submitAppy(' + row.ipmId + ')">提交</button>';
                                    htmlText += '<button  onclick="showEditPanel(' + row.ipmId + ')" class="btn btn-xs btn-warning">修改</button>';
                                }
                                if (hasP('purinv:purwarpro:del')) {
                                    htmlText += '<button  onclick="removeAppy(' + row.ipmId + ')" class="btn btn-xs btn-danger">删除</button>';

                                }
                            }
                            return htmlText;
                        }
                    }
                ];
                initData();
                js.table.search(table);
            } else {
                $("#ipmRemoveUserName").hide();
                $("#removeDate").hide();
                $("#toolbar").show();
                columns = [
                    {
                        title: '<input style="width: 16px;height: 16px" title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                        width: '30',
                        field: 'ipmId',
                        formatter: function (value, row, index) {
                            var disabled = 'disabled="disabled"';
                            if (row.ipmAppStatus == 1 || row.ipmAppStatus == 2) {
                                disabled = "";
                            }
                            var sessionUser = [[${session.user}]];
                            if (row.ipmProposerId != sessionUser.id) {
                                disabled = 'disabled="disabled"';
                            } else {
                                disabled = "";
                            }
                            return '<input  style="width: 16px;height: 16px" ' + disabled + ' id="cb_change' + row.ipmId + '" name="cb_change" data="' + row.ipmId + '"  type="checkbox" />';
                        }
                    },
                    {
                        title: '序号', field: 'ipmId', width: '50',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {title: '提报计划物料描述', field: 'ipmMatDesc', width: '150'},
                    {title: '标记数量', field: 'ipmNum'},
                    {title: '单位', field: 'ityNumUnit', width: '50'},
                    {title: '单价', field: 'ipmPrice', formatter: function (value, row, index) {
                            if(hasP('purinv:amount:view')){
                                return value;
                            }else {
                                return "***";
                            }
                        }},
                    {title: '提报计划物料标准号', field: 'ipmStandardNo'},
                    {
                        title: '项目编号', field: 'ipmInProjectCode', formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    {
                        title: '项目名称',
                        field: 'ipmInProjectName',
                        width: '150',
                        formatter: function (value, row, index) {
                            if (value == undefined || value == null) {
                                value = "--";
                            }
                            return value;
                        }
                    },
                    // {
                    //     title: '仓库类型', field: 'ipmItyType', width: '150', formatter: function (value, row, index) {
                    //         if (value == undefined) {
                    //             return "";
                    //         }
                    //         if (value == 'p') {
                    //             return "外购件库";
                    //         }
                    //         if (value == 'm') {
                    //             return "原料库";
                    //         }
                    //         if (value == 'h') {
                    //             return "成品库";
                    //         }
                    //         return value;
                    //     }
                    // },
                    {title: '仓库', field: 'ityWhiName'},
                    {
                        title: '标记人', field: 'ipmProposer', width: '70'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '标记时间', field: 'ipmDatePage', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '被标记物料项目编号', field: 'ityProCode', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '提交时间', field: 'ipmSubmitDate', width: '100'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '划拨说明', field: 'ipmRemark'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '划拨状态', field: 'ipmAppStatus'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            var html = '<label class="badge ' + applyStatusColor[value] + '">' + applyStatusText[value] + '</label>';
                            return html;
                        }
                    },
                    {
                        title: '驳回原因', field: 'ipmRejectReason'
                        , formatter: function (value, row, index) {
                            if (value == undefined) {
                                return "";
                            }
                            return value;
                        }
                    },
                    {
                        title: '操作', field: 'ipmId', width: '140',
                        formatter: function (value, row, index) {
                            var htmlText = "";

                            if (row.ipmDataStatus == null && (row.ipmAppStatus == 1 || row.ipmAppStatus == 2)) {
                                if (hasP('purinv:purwarpro:edit')) {
                                    htmlText += '<button class="btn btn-info btn-xs" onclick="submitAppy(' + row.ipmId + ')">提交</button>';
                                    htmlText += '<button  onclick="showEditPanel(' + row.ipmId + ')" class="btn btn-xs btn-warning">修改</button>';
                                }
                                if (hasP('purinv:purwarpro:del')) {
                                    htmlText += '<button  onclick="removeAppy(' + row.ipmId + ')" class="btn btn-xs btn-danger">删除</button>';

                                }
                            }
                            return htmlText;
                        }
                    }
                ];
                initData();
                js.table.search(table);
            }
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });
        /**
         * 保存修改
         */
        $("#btn-save").on('click', function () {
            js.modal.confirm("尊敬的用户，您确定要保存此修改吗？", function () {
                //验证通过式提交
                js.validSubmit({
                    formId: "modalForm",
                    url: ctx + "purchase/invPro/saveEdit",
                    data: new FormData($("#modalForm")[0]),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            js.modal.hide("modal-inventory-project");
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                        }
                    }
                });
            });
        });
        // 验证初始化
        js.validate.init("modalForm", {
            fields: {
                ipmInProjectCode: {
                    validators: {
                        notEmpty: {message: '请输入新项目编号'},
                        threshold: 6, //有6字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，6字符以上才开始）
                        callback: {
                            message: "项目号不存在",
                            callback: function (value, validator) {
                                var flag = false;
                                $.ajax({
                                    url: ctx + 'purchase/change/codeExist', // 请求路径
                                    type: 'POST',
                                    async: false,	// 同步请求，必须是false
                                    data: {
                                        ceoNeedProCode: $("#modalForm input[name='ipmInProjectCode']").val() // 请求参数
                                    },
                                    success: function (res) {
                                        flag = $.parseJSON(res).valid;
                                    }
                                });
                                return flag;
                            }
                        }
                    }
                },
                ipmInProjectName: {validators: {notEmpty: {message: '请输入新项目要名称'}}},
                ipmNum: {
                    validators: {
                        notEmpty: {message: '请输入标记数量'}
                    }
                },
            }
        });

        $("#btn-del-items").click(function () {
            removeAppy('');
        })
    });
</script>
</body>
</html>
